﻿Public Class ClassCorporate
    Public Shared Function AddCorporate(ByVal name As String, ByVal phone As String, ByVal adr As String, ByVal desc As String)
        Dim sql = "insert into tbl_corporate(corporate_name,phone,address,description,active) value(@name,@phone,@address,@desc,1)"
        Try
            Cmd.Parameters("@name") = name
            Cmd.Parameters("@phone") = phone
            Cmd.Parameters("@address") = adr
            Cmd.Parameters("@desc") = desc
            Cmd.ExecuteNonQuery(sql)
            myMsgbox.show("Add new Customer sucess!!!", "New Customer")
            Return True
        Catch ex As Exception
            myMsgbox.show("Add new Customer fail!!", "New Customer")
            Return False
        End Try
    End Function

    Public Shared Function editCorporate(ByVal id As Integer, ByVal name As String, ByVal phone As String, ByVal address As String, ByVal desc As String)
        Dim sql = "update tbl_corporate set corporate_name=@name,phone=@phone,address=@address,description=@desc where corporate_id=@id"
        Try
            Cmd.Parameters("@id") = id
            Cmd.Parameters("@name") = name
            Cmd.Parameters("@phone") = phone
            Cmd.Parameters("@address") = address
            Cmd.Parameters("@desc") = desc
            Cmd.ExecuteNonQuery(sql)
            myMsgbox.show("Update Corporate Success!!!", "Update Corporate")
            Return True
        Catch ex As Exception
            myMsgbox.show("Update Corporate Fail!!!", "Update Corporate")
            Return False
        End Try
    End Function

    Public Shadows Function deleteCorporate(ByVal id As Integer)
        Dim sql = "update tbl_corporate set active=false where corporate_id=@id"
        Try
            Cmd.Parameters("@id") = id
            Cmd.ExecuteNonQuery(sql)

            myMsgbox.show("Delete Corporate Success!!!", "Delete Corporate")
            Return True
        Catch ex As Exception
            myMsgbox.show("Delete Corporate Fail!!!", "Delete Corporate")
            Return False
        End Try
    End Function

    Public Shared Function loadCorporate(ByVal text As String) As DataTable
        Dim sql = "select * from tbl_corporate where active=true and corporate_name like @name"
        Try
            Cmd.Parameters("@name") = "%" & text & "%"
            Dim dt As New DataTable
            dt = Cmd.ExecuteDataTable(sql)
            Return dt
        Catch ex As Exception
            Return Nothing
        End Try
    End Function
End Class
